<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.2">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"wrr123.github.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="css伪类？css伪类是用来添加选择器的一些特殊效果。 语法伪类的语法： selector:pseudo-class &amp;#123;property: value;&amp;#125; CSS类也可以使用伪类： selector.class:pseudo-class &amp;#123;property: value;&amp;#125;  所有的伪类&#x2F;元素：     选择器 示例 示例说明     :checked in">
<meta property="og:type" content="article">
<meta property="og:title" content="faq-css">
<meta property="og:url" content="https://wrr123.github.io/2020/07/20/faq-css/index.html">
<meta property="og:site_name" content="一缕烟气">
<meta property="og:description" content="css伪类？css伪类是用来添加选择器的一些特殊效果。 语法伪类的语法： selector:pseudo-class &amp;#123;property: value;&amp;#125; CSS类也可以使用伪类： selector.class:pseudo-class &amp;#123;property: value;&amp;#125;  所有的伪类&#x2F;元素：     选择器 示例 示例说明     :checked in">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://localhost:4000/2020/07/20/faq-css/001.png">
<meta property="article:published_time" content="2020-07-20T04:55:19.000Z">
<meta property="article:modified_time" content="2022-02-18T02:52:04.407Z">
<meta property="article:author" content="田园隐士">
<meta property="article:tag" content="css">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://localhost:4000/2020/07/20/faq-css/001.png">

<link rel="canonical" href="https://wrr123.github.io/2020/07/20/faq-css/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>faq-css | 一缕烟气</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="一缕烟气" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">一缕烟气</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">沧海月明珠有泪，蓝田日暖玉生烟</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2020/07/20/faq-css/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          faq-css
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-07-20 12:55:19" itemprop="dateCreated datePublished" datetime="2020-07-20T12:55:19+08:00">2020-07-20</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%89%8D%E7%AB%AF/" itemprop="url" rel="index"><span itemprop="name">前端</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.4k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>3 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h4 id="css伪类？"><a href="#css伪类？" class="headerlink" title="css伪类？"></a>css伪类？</h4><p>css伪类是用来添加选择器的一些特殊效果。</p>
<h5 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h5><p>伪类的语法：</p>
<p><code>selector:pseudo-class &#123;property: value;&#125;</code></p>
<p>CSS类也可以使用伪类：</p>
<p><code>selector.class:pseudo-class &#123;property: value;&#125;</code></p>
<p><img src="http://localhost:4000/2020/07/20/faq-css/001.png" alt></p>
<p>所有的伪类/元素：</p>
<div class="table-container">
<table>
<thead>
<tr>
<th style="text-align:left">选择器</th>
<th style="text-align:left">示例</th>
<th style="text-align:left">示例说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-checked.html">:checked</a></td>
<td style="text-align:left">input:checked</td>
<td style="text-align:left">选择所有选中的表单元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/css/cssref/sel-disabled.html">:disabled</a></td>
<td style="text-align:left">input:disabled</td>
<td style="text-align:left">选择所有禁用的表单元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-empty.html">:empty</a></td>
<td style="text-align:left">p:empty</td>
<td style="text-align:left">选择所有没有子元素的p元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-enable.html">:enabled</a></td>
<td style="text-align:left">input:enabled</td>
<td style="text-align:left">选择所有启用的表单元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-first-of-type.html">:first-of-type</a></td>
<td style="text-align:left">p:first-of-type</td>
<td style="text-align:left">选择的每个 p 元素是其父元素的第一个 p 元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-in-range.html">:in-range</a></td>
<td style="text-align:left">input:in-range</td>
<td style="text-align:left">选择元素指定范围内的值</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-invalid.html">:invalid</a></td>
<td style="text-align:left">input:invalid</td>
<td style="text-align:left">选择所有无效的元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-last-child.html">:last-child</a></td>
<td style="text-align:left">p:last-child</td>
<td style="text-align:left">选择所有p元素的最后一个子元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-last-of-type.html">:last-of-type</a></td>
<td style="text-align:left">p:last-of-type</td>
<td style="text-align:left">选择每个p元素是其母元素的最后一个p元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-not.html">:not(selector)</a></td>
<td style="text-align:left">:not(p)</td>
<td style="text-align:left">选择所有p以外的元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-nth-child.html">:nth-child(n)</a></td>
<td style="text-align:left">p:nth-child(2)</td>
<td style="text-align:left">选择所有 p 元素的父元素的第二个子元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-nth-last-child.html">:nth-last-child(n)</a></td>
<td style="text-align:left">p:nth-last-child(2)</td>
<td style="text-align:left">选择所有p元素倒数的第二个子元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-nth-last-of-type.html">:nth-last-of-type(n)</a></td>
<td style="text-align:left">p:nth-last-of-type(2)</td>
<td style="text-align:left">选择所有p元素倒数的第二个为p的子元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-nth-of-type.html">:nth-of-type(n)</a></td>
<td style="text-align:left">p:nth-of-type(2)</td>
<td style="text-align:left">选择所有p元素第二个为p的子元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-only-of-type.html">:only-of-type</a></td>
<td style="text-align:left">p:only-of-type</td>
<td style="text-align:left">选择所有仅有一个子元素为p的元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-only-child.html">:only-child</a></td>
<td style="text-align:left">p:only-child</td>
<td style="text-align:left">选择所有仅有一个子元素的p元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-optional.html">:optional</a></td>
<td style="text-align:left">input:optional</td>
<td style="text-align:left">选择没有”required”的元素属性</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-out-of-range.html">:out-of-range</a></td>
<td style="text-align:left">input:out-of-range</td>
<td style="text-align:left">选择指定范围以外的值的元素属性</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-read-only.html">:read-only</a></td>
<td style="text-align:left">input:read-only</td>
<td style="text-align:left">选择只读属性的元素属性</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-read-write.html">:read-write</a></td>
<td style="text-align:left">input:read-write</td>
<td style="text-align:left">选择没有只读属性的元素属性</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-required.html">:required</a></td>
<td style="text-align:left">input:required</td>
<td style="text-align:left">选择有”required”属性指定的元素属性</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-root.html">:root</a></td>
<td style="text-align:left">root</td>
<td style="text-align:left">选择文档的根元素</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-target.html">:targets</a></td>
<td style="text-align:left">#news:target</td>
<td style="text-align:left">选择当前活动#news元素(点击URL包含锚的名字)</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-valid.html">:valid</a></td>
<td style="text-align:left">input:valid</td>
<td style="text-align:left">选择所有有效值的属性</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-link.html">:link</a></td>
<td style="text-align:left">a:link</td>
<td style="text-align:left">选择所有未访问链接</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-visited.html">:visited</a></td>
<td style="text-align:left">a:visited</td>
<td style="text-align:left">选择所有访问过的链接</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-active.html">:active</a></td>
<td style="text-align:left">a:active</td>
<td style="text-align:left">选择正在活动链接</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-hover.html">:hover</a></td>
<td style="text-align:left">a:hover</td>
<td style="text-align:left">把鼠标放在链接上的状态</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-focus.html">:focus</a></td>
<td style="text-align:left">input:focus</td>
<td style="text-align:left">选择元素输入后具有焦点</td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-firstletter.html">:first-letter</a></td>
<td style="text-align:left">p:first-letter</td>
<td style="text-align:left">选择每个<p> 元素的第一个字母</p></td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-firstline.html">:first-line</a></td>
<td style="text-align:left">p:first-line</td>
<td style="text-align:left">选择每个<p> 元素的第一行</p></td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-firstchild.html">:first-child</a></td>
<td style="text-align:left">p:first-child</td>
<td style="text-align:left">选择器匹配属于任意元素的第一个子元素的 <p> 元素</p></td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-before.html">:before</a></td>
<td style="text-align:left">p:before</td>
<td style="text-align:left">在每个<p>元素之前插入内容</p></td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-after.html">:after</a></td>
<td style="text-align:left">p:after</td>
<td style="text-align:left">在每个<p>元素之后插入内容</p></td>
</tr>
<tr>
<td style="text-align:left"><a target="_blank" rel="noopener" href="https://www.runoob.com/cssref/sel-lang.html">:lang(<em>language</em>)</a></td>
<td style="text-align:left">p:lang(it)</td>
<td style="text-align:left">为<p>元素的lang属性选择一个开始值</p></td>
</tr>
</tbody>
</table>
</div>
<h4 id="jQuery中的closest-selector-选择器"><a href="#jQuery中的closest-selector-选择器" class="headerlink" title="jQuery中的closest(selector)选择器"></a>jQuery中的<code>closest(selector)</code>选择器</h4><h5 id="描述：从元素本身开始，在DOM树上逐级向上级元素匹配，并返回最先匹配的祖先元素。"><a href="#描述：从元素本身开始，在DOM树上逐级向上级元素匹配，并返回最先匹配的祖先元素。" class="headerlink" title="描述：从元素本身开始，在DOM树上逐级向上级元素匹配，并返回最先匹配的祖先元素。"></a>描述：从元素本身开始，在DOM树上逐级向上级元素匹配，并返回最先匹配的祖先元素。</h5><h5 id="一个例子"><a href="#一个例子" class="headerlink" title="一个例子"></a>一个例子</h5><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="string">&#x27;li.item-a&#x27;</span>).<span class="title function_">closest</span>(<span class="string">&#x27;ul&#x27;</span>).<span class="title function_">css</span>(<span class="string">&#x27;background-color&#x27;</span>, <span class="string">&#x27;red&#x27;</span>);</span><br></pre></td></tr></table></figure>
<h4 id="如何让image的图片充满父节点"><a href="#如何让image的图片充满父节点" class="headerlink" title="如何让image的图片充满父节点?"></a>如何让image的图片充满父节点?</h4><h5 id="方案1"><a href="#方案1" class="headerlink" title="方案1"></a>方案1</h5><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">div</span> image &#123;</span><br><span class="line">	<span class="attribute">height</span>: <span class="number">100%</span>;</span><br><span class="line">	<span class="attribute">width</span>: <span class="number">100%</span>;</span><br><span class="line">	<span class="attribute">object-fit</span>: cover;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="图片拉宽或者拉高时，使图片失真？"><a href="#图片拉宽或者拉高时，使图片失真？" class="headerlink" title="图片拉宽或者拉高时，使图片失真？"></a>图片拉宽或者拉高时，使图片失真？</h4><p>有点类似上面的css，</p>
<ul>
<li><p>使用img的话</p>
<p><code>object-fit: cover;</code></p>
</li>
<li><p>使用background-image的话</p>
<p><code>background-size: cover;</code></p>
</li>
</ul>
<h4 id="多个背景图片"><a href="#多个背景图片" class="headerlink" title="多个背景图片"></a>多个背景图片</h4><p>在css3里面，你可以在一个标签元素里应用多个背景图片。在引用图片之间用逗号<code>,</code>隔开。第一个图片是定位在元素最上面的背景，后面的背景图片一次在它的下面，如下:</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">background-image</span>: <span class="built_in">url</span>(<span class="string">top-image.jpg</span>), <span class="built_in">url</span>(<span class="string">middle-image.jpg</span>), <span class="built_in">url</span>(<span class="string">bottom-image.jpg</span>);</span><br></pre></td></tr></table></figure>
<h4 id="div被遮挡，让一个div层浮在最上层的方法"><a href="#div被遮挡，让一个div层浮在最上层的方法" class="headerlink" title="div被遮挡，让一个div层浮在最上层的方法"></a>div被遮挡，让一个div层浮在最上层的方法</h4><p>首先设置<code>position</code>属性为<code>absolute,relative或fixed</code>，</p>
<p><strong>必须position为以上三个属性时，z-index才能层级体现出来，才能够起作用</strong></p>
<p><code>z-index</code>可以定义一个数值，其值越大代表越置前。</p>
<p>若定义为-1，表示最底层。</p>
<h4 id="隐藏滚动条，但依然可以滚动内容"><a href="#隐藏滚动条，但依然可以滚动内容" class="headerlink" title="隐藏滚动条，但依然可以滚动内容"></a>隐藏滚动条，但依然可以滚动内容</h4><h5 id="方式一：计算滚动条的长度，并隐藏起来"><a href="#方式一：计算滚动条的长度，并隐藏起来" class="headerlink" title="方式一：计算滚动条的长度，并隐藏起来"></a>方式一：计算滚动条的长度，并隐藏起来</h5><p>一个栗子：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;outer-container&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;inner-container&quot;</span>&gt;</span></span><br><span class="line">    	......</span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="selector-class">.outer-container</span>&#123;</span><br><span class="line">	<span class="attribute">width</span>: <span class="number">360px</span>;</span><br><span class="line">	<span class="attribute">height</span>: <span class="number">200px</span>;</span><br><span class="line">	<span class="attribute">position</span>: relative;</span><br><span class="line">	<span class="attribute">overflow</span>: hidden;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-class">.inner-container</span>&#123;</span><br><span class="line">	<span class="attribute">position</span>: absolute;</span><br><span class="line">	<span class="attribute">left</span>: <span class="number">0</span>;</span><br><span class="line">	<span class="attribute">top</span>: <span class="number">0</span>;</span><br><span class="line">	<span class="attribute">right</span>: -<span class="number">17px</span>;</span><br><span class="line">	<span class="attribute">bottom</span>: <span class="number">0</span>;</span><br><span class="line">	<span class="attribute">overflow-x</span>: hidden;</span><br><span class="line">	<span class="attribute">overflow-y</span>: scroll;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="方式二：使用三个容器包围起来，不需要计算滚动条的宽度"><a href="#方式二：使用三个容器包围起来，不需要计算滚动条的宽度" class="headerlink" title="方式二：使用三个容器包围起来，不需要计算滚动条的宽度"></a>方式二：使用三个容器包围起来，不需要计算滚动条的宽度</h5><p>一个栗子：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;outer-container&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;inner-container&quot;</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;content&quot;</span>&gt;</span></span><br><span class="line">           ......</span><br><span class="line">       <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.element</span>, <span class="selector-class">.outer-container</span> &#123;</span><br><span class="line">  <span class="attribute">width</span>: <span class="number">200px</span>;</span><br><span class="line">  <span class="attribute">height</span>: <span class="number">200px</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.outer-container</span> &#123;</span><br><span class="line">  <span class="attribute">border</span>: <span class="number">5px</span> solid purple;</span><br><span class="line">  <span class="attribute">position</span>: relative;</span><br><span class="line">  <span class="attribute">overflow</span>: hidden;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.inner-container</span> &#123;</span><br><span class="line">  <span class="attribute">position</span>: absolute;</span><br><span class="line">  <span class="attribute">left</span>: <span class="number">0</span>;</span><br><span class="line">  <span class="attribute">overflow-x</span>: hidden;</span><br><span class="line">  <span class="attribute">overflow-y</span>: scroll;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.inner-container</span>::-webkit-scrollbar &#123;</span><br><span class="line">  <span class="attribute">display</span>: none;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="方式三：css-隐藏滚动条"><a href="#方式三：css-隐藏滚动条" class="headerlink" title="方式三：css 隐藏滚动条"></a>方式三：css 隐藏滚动条</h5><p>自定义滚动条的伪对象选择器  <code>::webkit-scrollbar</code></p>
<blockquote>
<p>chrome 和Safari</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.element</span>::-webkit-scrollbar &#123; <span class="attribute">width</span>: <span class="number">0</span> <span class="meta">!important</span> &#125;</span><br></pre></td></tr></table></figure>
<p>IE 10+</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.element</span> &#123; -ms-<span class="attribute">overflow</span>-style: none; &#125;</span><br></pre></td></tr></table></figure>
<p>Firefox</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.element</span> &#123; <span class="attribute">overflow</span>: -moz-scrollbars-none; &#125;</span><br></pre></td></tr></table></figure>
</blockquote>
<h4 id="css-的注释"><a href="#css-的注释" class="headerlink" title="css 的注释"></a>css 的注释</h4><h5 id="单行注释"><a href="#单行注释" class="headerlink" title="单行注释"></a>单行注释</h5><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- 注释内容 --&gt;</span><br><span class="line"><span class="comment">/* 注释内容 */</span></span><br></pre></td></tr></table></figure>
<h5 id="区域注释"><a href="#区域注释" class="headerlink" title="区域注释"></a>区域注释</h5><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*=S 注释内容 */</span></span><br><span class="line">...</span><br><span class="line">...</span><br><span class="line"><span class="comment">/*=E 注释内容 */</span></span><br></pre></td></tr></table></figure>
<h5 id="协助注释"><a href="#协助注释" class="headerlink" title="协助注释"></a>协助注释</h5><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*=S 注释内容[修改人和修改时间] */</span></span><br><span class="line">...</span><br><span class="line">...</span><br><span class="line"><span class="comment">/*=E 注释内容[修改人和修改时间] */</span></span><br></pre></td></tr></table></figure>

    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/css/" rel="tag"># css</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/07/15/js%E6%AD%A3%E5%88%99%E7%9A%84%E5%87%A0%E4%B8%AA%E6%96%B9%E6%B3%95-%E4%B8%80/" rel="prev" title="js正则的几个方法(一)">
      <i class="fa fa-chevron-left"></i> js正则的几个方法(一)
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/07/21/nacos%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/" rel="next" title="nacos基础教程">
      nacos基础教程 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#css%E4%BC%AA%E7%B1%BB%EF%BC%9F"><span class="nav-number">1.</span> <span class="nav-text">css伪类？</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E8%AF%AD%E6%B3%95"><span class="nav-number">1.1.</span> <span class="nav-text">语法</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#jQuery%E4%B8%AD%E7%9A%84closest-selector-%E9%80%89%E6%8B%A9%E5%99%A8"><span class="nav-number">2.</span> <span class="nav-text">jQuery中的closest(selector)选择器</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%8F%8F%E8%BF%B0%EF%BC%9A%E4%BB%8E%E5%85%83%E7%B4%A0%E6%9C%AC%E8%BA%AB%E5%BC%80%E5%A7%8B%EF%BC%8C%E5%9C%A8DOM%E6%A0%91%E4%B8%8A%E9%80%90%E7%BA%A7%E5%90%91%E4%B8%8A%E7%BA%A7%E5%85%83%E7%B4%A0%E5%8C%B9%E9%85%8D%EF%BC%8C%E5%B9%B6%E8%BF%94%E5%9B%9E%E6%9C%80%E5%85%88%E5%8C%B9%E9%85%8D%E7%9A%84%E7%A5%96%E5%85%88%E5%85%83%E7%B4%A0%E3%80%82"><span class="nav-number">2.1.</span> <span class="nav-text">描述：从元素本身开始，在DOM树上逐级向上级元素匹配，并返回最先匹配的祖先元素。</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E4%B8%80%E4%B8%AA%E4%BE%8B%E5%AD%90"><span class="nav-number">2.2.</span> <span class="nav-text">一个例子</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%A6%82%E4%BD%95%E8%AE%A9image%E7%9A%84%E5%9B%BE%E7%89%87%E5%85%85%E6%BB%A1%E7%88%B6%E8%8A%82%E7%82%B9"><span class="nav-number">3.</span> <span class="nav-text">如何让image的图片充满父节点?</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%96%B9%E6%A1%881"><span class="nav-number">3.1.</span> <span class="nav-text">方案1</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%9B%BE%E7%89%87%E6%8B%89%E5%AE%BD%E6%88%96%E8%80%85%E6%8B%89%E9%AB%98%E6%97%B6%EF%BC%8C%E4%BD%BF%E5%9B%BE%E7%89%87%E5%A4%B1%E7%9C%9F%EF%BC%9F"><span class="nav-number">4.</span> <span class="nav-text">图片拉宽或者拉高时，使图片失真？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%A4%9A%E4%B8%AA%E8%83%8C%E6%99%AF%E5%9B%BE%E7%89%87"><span class="nav-number">5.</span> <span class="nav-text">多个背景图片</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#div%E8%A2%AB%E9%81%AE%E6%8C%A1%EF%BC%8C%E8%AE%A9%E4%B8%80%E4%B8%AAdiv%E5%B1%82%E6%B5%AE%E5%9C%A8%E6%9C%80%E4%B8%8A%E5%B1%82%E7%9A%84%E6%96%B9%E6%B3%95"><span class="nav-number">6.</span> <span class="nav-text">div被遮挡，让一个div层浮在最上层的方法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%9A%90%E8%97%8F%E6%BB%9A%E5%8A%A8%E6%9D%A1%EF%BC%8C%E4%BD%86%E4%BE%9D%E7%84%B6%E5%8F%AF%E4%BB%A5%E6%BB%9A%E5%8A%A8%E5%86%85%E5%AE%B9"><span class="nav-number">7.</span> <span class="nav-text">隐藏滚动条，但依然可以滚动内容</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%96%B9%E5%BC%8F%E4%B8%80%EF%BC%9A%E8%AE%A1%E7%AE%97%E6%BB%9A%E5%8A%A8%E6%9D%A1%E7%9A%84%E9%95%BF%E5%BA%A6%EF%BC%8C%E5%B9%B6%E9%9A%90%E8%97%8F%E8%B5%B7%E6%9D%A5"><span class="nav-number">7.1.</span> <span class="nav-text">方式一：计算滚动条的长度，并隐藏起来</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%96%B9%E5%BC%8F%E4%BA%8C%EF%BC%9A%E4%BD%BF%E7%94%A8%E4%B8%89%E4%B8%AA%E5%AE%B9%E5%99%A8%E5%8C%85%E5%9B%B4%E8%B5%B7%E6%9D%A5%EF%BC%8C%E4%B8%8D%E9%9C%80%E8%A6%81%E8%AE%A1%E7%AE%97%E6%BB%9A%E5%8A%A8%E6%9D%A1%E7%9A%84%E5%AE%BD%E5%BA%A6"><span class="nav-number">7.2.</span> <span class="nav-text">方式二：使用三个容器包围起来，不需要计算滚动条的宽度</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%96%B9%E5%BC%8F%E4%B8%89%EF%BC%9Acss-%E9%9A%90%E8%97%8F%E6%BB%9A%E5%8A%A8%E6%9D%A1"><span class="nav-number">7.3.</span> <span class="nav-text">方式三：css 隐藏滚动条</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#css-%E7%9A%84%E6%B3%A8%E9%87%8A"><span class="nav-number">8.</span> <span class="nav-text">css 的注释</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%8D%95%E8%A1%8C%E6%B3%A8%E9%87%8A"><span class="nav-number">8.1.</span> <span class="nav-text">单行注释</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%8C%BA%E5%9F%9F%E6%B3%A8%E9%87%8A"><span class="nav-number">8.2.</span> <span class="nav-text">区域注释</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%8D%8F%E5%8A%A9%E6%B3%A8%E9%87%8A"><span class="nav-number">8.3.</span> <span class="nav-text">协助注释</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">田园隐士</p>
  <div class="site-description" itemprop="description">talk is cheap, show me the code</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">347</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">53</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">115</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">田园隐士</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">587k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">8:53</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

  

</body>
</html>
